package com.ruoyi.web.controller.opinion;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.opinion.domain.Opinion;
import com.ruoyi.opinion.service.IOpinionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 意见反馈Controller
 *
 * @author ruoyi
 * @date 2021-11-16
 */
@RestController
@RequestMapping("/opinion/opinion")
public class OpinionController extends BaseController
{
    @Autowired
    private IOpinionService opinionService;

    /**
     * 查询意见反馈列表
     */
    @PreAuthorize("@ss.hasPermi('opinion:opinion:list')")
    @GetMapping("/list")
    public TableDataInfo list(Opinion opinion)
    {
        startPage();
        List<Opinion> list = opinionService.selectOpinionList(opinion);
        return getDataTable(list);
    }

    /**
     * 导出意见反馈列表
     */
    @PreAuthorize("@ss.hasPermi('opinion:opinion:export')")
    @Log(title = "意见反馈", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Opinion opinion)
    {
        List<Opinion> list = opinionService.selectOpinionList(opinion);
        ExcelUtil<Opinion> util = new ExcelUtil<Opinion>(Opinion.class);
        return util.exportExcel(list, "意见反馈数据");
    }

    /**
     * 获取意见反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('opinion:opinion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(opinionService.selectOpinionById(id));
    }

    /**
     * 新增意见反馈
     */
    @PreAuthorize("@ss.hasPermi('opinion:opinion:add')")
    @Log(title = "意见反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Opinion opinion)
    {
        return toAjax(opinionService.insertOpinion(opinion));
    }

    /**
     * 修改意见反馈
     */
    @PreAuthorize("@ss.hasPermi('opinion:opinion:edit')")
    @Log(title = "意见反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Opinion opinion)
    {
        opinion.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(opinionService.updateOpinion(opinion));
    }

    /**
     * 处理意见反馈
     */
    @PreAuthorize("@ss.hasPermi('opinion:opinion:edit')")
    @Log(title = "处理意见反馈", businessType = BusinessType.UPDATE)
    @PutMapping("/solve")
    public AjaxResult solve(@RequestBody Opinion opinion)
    {
        opinion.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        opinion.setSolveUserId(getUserId());
        opinion.setSolveTime(new Date());
        opinion.setSolveState(DicConstants.SYS_Y.getCode());
        return toAjax(opinionService.updateOpinion(opinion));
    }
  /*  *//**
     * 处理意见反馈
     *//*
    @PreAuthorize("@ss.hasPermi('opinion:opinion:edit')")
    @Log(title = "处理意见反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult solve(@RequestBody Long[] ids)
    {
        opinion.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        opinion.setSolveUserId(getUserId());
        opinion.setSolveTime(new Date());
        opinion.setSolveState(DicConstants.SYS_Y.getCode());
        return toAjax(opinionService.updateOpinion(opinion));
    }*/
    /**
     * 删除意见反馈
     */
    @PreAuthorize("@ss.hasPermi('opinion:opinion:remove')")
    @Log(title = "意见反馈", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(opinionService.logicDeleteOpinion(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
